package com.weixing.mall.provider.controller.rpc;

import com.weixing.mall.base.wrapper.Result;
import com.weixing.mall.base.wrapper.ResultUtil;
import com.weixing.mall.core.support.BaseController;
import com.weixing.mall.provider.api.model.dto.ProfitCalcDto;
import com.weixing.mall.provider.service.IAgentProfitService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 代理获利
 *
 * @author siashan
 * @since v1.0
 */
@Slf4j
@RestController
@RequestMapping("/api/agent/profit")
public class AgentProfitRpcController extends BaseController {
    @Autowired
    private IAgentProfitService agentProfitService;

    /**
     * 方法描述: 计算代理商返利
     *
     * @param   profitCalc 返利计算
     * @return 结果
     */
    @PostMapping("calc")
    public Result calcProfit(@RequestBody ProfitCalcDto profitCalc) {
        if (log.isDebugEnabled()) {
            log.debug("收到代理获利计算请求，订单编号{}", profitCalc.getOrderSn());
        }
        agentProfitService.calcProfit(profitCalc);
        if (log.isDebugEnabled()) {
            log.debug("代理获利计算请求执行完毕，订单编号{}", profitCalc.getOrderSn());
        }
        // 回调通知
        return ResultUtil.success();
    }


    /**
     * 方法描述: 活动结算计算代理商返利
     *
     * @param actId 活动id
     * @return 结果
     */
    @PostMapping("actCalc")
    public Result actCalcProfit(Long actId) {
        agentProfitService.actCalcProfit(actId);
        return ResultUtil.success();
    }


    /**
     * 方法描述: 回滚代理商返利
     *
     * @param orderId 订单id
     * @return 结果
     */
    @PostMapping("unProfit")
    public Result unProfit(Long orderId) {
        agentProfitService.unProfit(orderId);
        return ResultUtil.success();
    }

}
